Numbers not adding up? (What am I not understanding here?) [closed]

Posted by Milo on Game Development See other posts from Game Development or by Milo
Published on 2012-04-05T18:58:57Z Indexed on 2012/04/06 5:43 UTC
Read the original article Hit count: 280

Filed under:
|
|

I have the following output: enter image description here

Short version: The last numbers on the S= lines increase by H and SHOULD theoretically be linearly decreasing, ex: -285,-290,-295...but the fourth one jumps to -252. Yet, every other number is linearly increasing. Why is that and how could I fix that?

To explain the numbers, it comes from slider value changed. I have a slider whose value is used to generate the float on the next line. Everything should be growing linearly here.

This value is used to determine the size of a flow layout and it is also used in conjunction with a scrollbar. But basically I have a background for the flow layout and that number is the start location for rendering it. The numbers should linearly change to create a smooth transition but when that one jumps, it looks weird on screen and I dont understand why the numbers are jumping every X slider value changes. Mathematically what could be causing this?

Here is the code for rendering the background and the function that is called when value changes:

void LobbyTableManager::renderBG( GraphicsContext* g, agui::Rectangle& absRect, agui::Rectangle& childRect )
    {

        float scale = 0.35f;
        int w = m_bgSprite->getWidth() * getTableScale() * scale;
        int h = m_bgSprite->getHeight() * getTableScale() * scale;

        int numX = ceil(absRect.getWidth() / (float)w) + 2;
        int numY = ceil(absRect.getHeight() / (float)h) + 2;

        int startY = childRect.getY();

    int numAttempts = 0;
    while(startY + h < absRect.getY() && numAttempts < 1000)
    {
        startY += h;
        if(moo)
        {
            std::cout << startY << ",";
        }

        numAttempts++;
    }

    g->holdDrawing();
    for(int i = 0; i < numX; ++i)
    {
        for(int j = 0; j < numY; ++j)
        {
            g->drawScaledSprite(m_bgSprite,0,0,m_bgSprite->getWidth(),m_bgSprite->getHeight(),
                absRect.getX() + (i * w) + (offsetX),absRect.getY() + (j * h) + startY,w,h,0);
        }
    }
    g->unholdDrawing();
    g->setClippingRect(cx,cy,cw,ch);
}

void LobbyTableManager::setTableScale( float scale )
{
    scale += 0.3f;
    scale *= 2.0f;
    float scrollRel = m_vScroll->getRelativeValue();
    setScale(scale);
    rescaleTables();
    resizeFlow();

    updateScrollBars();
    float newVal = scrollRel * m_vScroll->getMaxValue();

    m_vScroll->setValue(newVal);


}

void LobbyTableManager::valueChanged( agui::VScrollBar* source,int val )
{
    m_flow->setLocation(0,-val);

}

Any insight on mathematically why the anomaly might happen every Nth time would be helpful. I just dont understand why if every number linearly increates it jumps from -295 to -252!

Thanks

© Game Development or respective owner

Related posts about c++

Related posts about 2d